package com.keldian.mobilesafe.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Administrator on 15-12-9.
 */
public class SharePrefenceTool {

    private static final String FILE_NAME = "mobilesafe";
    private static final String MODE_NAME = "update";
    private static final String VESION_CODE = "versionCode";
    private static final String FDPWD = "fdPwd";
    private static final String FD_SET = "fdSet";
    private static final String FD_SIM = "fdSim";
    private static final String SAFEMOBILE = "SafeMobile";
    private static final String PROTECTING = "Protecting";
    private static final String GPSLOCATION = "GPS";
    private static final String DIALBGINDEX = "DIALBGINDEX";


    public static boolean getSharePreferences(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE).
                getBoolean(MODE_NAME, false);
    }


    public static void setSharePreferences(Context context, boolean value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putBoolean(MODE_NAME, value);
        editor.commit();
    }

    //根据是否有最新版本的情况，查看是否需要升级
    public static int getVersionCode(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getInt(VESION_CODE, 0);
    }


    public static void setVersionCode(Context context, int value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putInt(VESION_CODE, value);
        editor.commit();
    }

    //是否有跨版本的升级包
    public static String getUpdateVersion(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getString(VESION_CODE, "1.0");
    }


    public static void setUpdateVersion(Context context, String value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putString(VESION_CODE, value);
        editor.commit();
    }

    //是否设置手机防盗密码
    public static String getFDPwd(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getString(FDPWD, null);
    }


    public static void setFDPwd(Context context, String value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putString(FDPWD, value);
        editor.commit();
    }

    //是否设置手机防盗
    public static boolean getFD(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getBoolean(FD_SET, false);
    }


    public static void setFD(Context context, boolean value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putBoolean(FD_SET, value);
        editor.commit();
    }


    //是否绑定Sim卡
    public static String getSim(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getString(FD_SIM, null);
    }

    public static void setSim(Context context, String value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putString(FD_SIM, value);
        editor.commit();
    }

    //是否绑定被盗回执短信手机
    public static String getSafeMobile(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getString(SAFEMOBILE, null);
    }

    public static void setSafeMobile(Context context, String value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putString(SAFEMOBILE, value);
        editor.commit();
    }

    //是否开启手机保护
    public static boolean getProtecting(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getBoolean(PROTECTING, false);
    }

    public static void setProtecting(Context context, boolean value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putBoolean(PROTECTING, value);
        editor.commit();
    }


    //是否获取GPS
    public static String getGPS(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getString(GPSLOCATION, null);
    }

    public static void setGPS(Context context, String value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putString(GPSLOCATION, value);
        editor.commit();
    }


    //save the dial from city background
    public static int getDialBackgroundIndex(Context context) {
        return context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE)
                .getInt(DIALBGINDEX, 0);
    }

    public static void setDialBackgroundIndex(Context context, int value) {
        SharedPreferences.Editor editor = context.getSharedPreferences(FILE_NAME,
                Context.MODE_APPEND).edit();
        editor.putInt(DIALBGINDEX, value);
        editor.commit();
    }


    public static void putInt(String key, int value, Context ctx) {
        SharedPreferences sp = ctx.getSharedPreferences("config",
                Context.MODE_PRIVATE);
        sp.edit().putInt(key, value).commit();
    }

    public static int getInt(String key, int defValue, Context ctx) {
        SharedPreferences sp = ctx.getSharedPreferences("config",
                Context.MODE_PRIVATE);
        return sp.getInt(key, defValue);
    }


}
